# -*- coding: utf-8 -*-
# @Author: garlic
# @Date:   2019-04-08 16:05:58
# @Last Modified by:   garlic
# @Last Modified time: 2019-04-08 16:05:58

import time
import logging
import const
import hashlib
import socket
import uuid

def getNow():
    return time.strftime('%Y-%m-%d %H:%M:%S',time.localtime(time.time()))

def genTradeNo():
    return  uuid.uuid4()

def getMacAddress():
    mac = uuid.UUID(int=uuid.getnode()).hex[-12:]
    return ":".join([mac[e:e + 2] for e in range(0, 11, 2)])

def __md5(src):
    m2 = hashlib.md5()
    m2.update(src)
    return m2.hexdigest().upper()

def doSign(__map):
    logging.info(__map)
    sorted_keys = []
    for k,v in __map.items():
        sorted_keys.append(k)
    sorted_keys = sorted(sorted_keys)

    signStrings = ""
    for k in sorted_keys:
        v = '{}'.format(__map[k])
        if  v!= "":
            signStrings = signStrings+k+"="+v+"&"
    signStrings += "APP_SECRET=" + const.GF_APP_SECRET
    logging.info("待签名数据:"+signStrings)
    ret  =  __md5(signStrings)
    logging.info("签名结果:" + ret)
    return  ret

